package ${basePackage}.controller.admin;



import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import klg.common.model.EasyUIPage;
import klg.common.model.JsonData;
import ${basePackage}.entity.${entityName};
import ${basePackage}.service.${entityName}Service;



/**
 *
 * 
 * Generated by fieldmeta at ${nowTime}
 *
 */

@Controller("admin${entityName}Controller")
@RequestMapping("/admin/action/${entityName_all_lowcase}")
public class ${entityName}Controller {
	@Autowired
	${entityName}Service ${entityName_first_lowcase}Service;
	
	@ResponseBody
	@RequestMapping("/add")
	public JsonData add(
			@ModelAttribute ${entityName} ${entityName_first_lowcase}){
		
		${entityName_first_lowcase}Service.save(${entityName_first_lowcase});
		return JsonData.success();
	}
	
	
	@ResponseBody
	@RequestMapping("/edit")
	public JsonData edit(
			@ModelAttribute ${entityName} ${entityName_first_lowcase}){
		
		${entityName_first_lowcase}Service.update(${entityName_first_lowcase});
		return JsonData.success();
	}
	
	@ResponseBody
	@RequestMapping("/delete")
	public JsonData delete(
			@RequestParam Long id){
		
		${entityName_first_lowcase}Service.delete(id);
		return JsonData.success();
	}
	
	@ResponseBody
	@RequestMapping("/findpage")
	public EasyUIPage findpage(
			@ModelAttribute ${entityName} ${entityName_first_lowcase},
			@RequestParam int page,
			@RequestParam int rows){
		Pageable pageable=new PageRequest(page<1?0:page-1, rows, new Sort(Direction.DESC,"id"));
		Page<${entityName}> pageData=${entityName_first_lowcase}Service.findPage(${entityName_first_lowcase}, pageable);
		return new EasyUIPage(pageData);
	}
	
	@ResponseBody
	@RequestMapping("/findlist")
	public JsonData findlist(
			@ModelAttribute ${entityName} ${entityName_first_lowcase}){
		
		List<${entityName}> listData=${entityName_first_lowcase}Service.findList(${entityName_first_lowcase}, new Sort(Direction.DESC,"id"));
		return JsonData.success(listData);
	}	
}
